#include "delge_squirrelgraphics.h"

void s_Graphics_RegisterFunctions (HSQUIRRELVM v)
{
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ClearScreen,			_SC("ClearScreen"),						_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Flip,					_SC("Flip"),							_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_SwitchToFullscreen,		_SC("SwitchToFullscreen"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_SwitchToWindowed,		_SC("SwitchToWindowed"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ToggleFullscreen,		_SC("ToggleFullscreen"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_SetBlendMode,			_SC("SetBlendMode"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetBlendMode,			_SC("GetBlendMode"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_SetGlobalColor,			_SC("SetGlobalColor"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetGlobalColorRed,		_SC("GetGlobalColorRed"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetGlobalColorGreen,	_SC("GetGlobalColorGreen"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetGlobalColorBlue,		_SC("GetGlobalColorBlue"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetGlobalColorAlpha,	_SC("GetGlobalColorAlpha"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_LoadTexture,			_SC("LoadTextureA"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_UnloadTexture,			_SC("UnloadTextureA"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_LoadFont,				_SC("LoadFontA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_UnloadFont,				_SC("UnloadFontA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawRect,				_SC("DrawRect"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawTexture,			_SC("DrawTextureA"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawTextureArea,		_SC("DrawTextureAreaA"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawText,				_SC("DrawTextA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawMesh,				_SC("DrawMeshA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawModel,				_SC("DrawModelA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawSprite,				_SC("DrawSpriteA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DrawCamera,				_SC("DrawCameraA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_TextWidth,				_SC("TextWidthA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_TextHeight,				_SC("TextHeightA"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_BindTexture,			_SC("BindTextureA"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_PushWorldMatrix,		_SC("PushWorldMatrix"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_PopWorldMatrix,			_SC("PopWorldMatrix"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_TranslateWorld,			_SC("TranslateWorld"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_RotateWorldPitch,		_SC("RotateWorldPitch"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_RotateWorldYaw,			_SC("RotateWorldYaw"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_RotateWorldRoll,		_SC("RotateWorldRoll"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ScaleWorld,				_SC("ScaleWorld"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ResetWorld,				_SC("ResetWorld"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ResetProjection,		_SC("ResetProjection"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ProjectX,				_SC("ProjectX"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_ProjectY,				_SC("ProjectY"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_SetViewport,			_SC("SetViewport"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetScreenWidth,			_SC("GetScreenWidth"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_GetScreenHeight,		_SC("GetScreenHeight"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Begin2DRendering,		_SC("Begin2DRendering"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Begin3DRendering,		_SC("Begin3DRendering"),				_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_EnableLighting,			_SC("EnableLighting"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_DisableLighting,		_SC("DisableLighting"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_CreateCubeMesh,			_SC("CreateCubeMeshA"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_CreatePlaneMesh,		_SC("CreatePlaneMeshA"),				_SC("*"));
}

SQInteger s_Graphics_ClearScreen (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->ClearScreen();

	return 0;
}

SQInteger s_Graphics_Flip (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->Flip();

	return 0;
}

SQInteger s_Graphics_SwitchToFullscreen (HSQUIRRELVM v)
{
	DelGEEvent oEvent;
	oEvent.eType = DelGE_Event_Game_SwitchToFullscreen;
	oEvent.GameData.pData = NULL;
	EventManager::PushEvent(oEvent);

	return 0;
}

SQInteger s_Graphics_SwitchToWindowed (HSQUIRRELVM v)
{
	DelGEEvent oEvent;
	oEvent.eType = DelGE_Event_Game_SwitchToWindowed;
	oEvent.GameData.pData = NULL;
	EventManager::PushEvent(oEvent);

	return 0;
}

SQInteger s_Graphics_ToggleFullscreen (HSQUIRRELVM v)
{
	DelGEEvent oEvent;
	oEvent.eType = DelGE_Event_Game_ToggleFullscreen;
	oEvent.GameData.pData = NULL;
	EventManager::PushEvent(oEvent);

	return 0;
}

SQInteger s_Graphics_SetBlendMode (HSQUIRRELVM v)
{
	SQInteger				eMode;

	sq_getinteger			(v, 2, &eMode);

	Globals::pGame->GetEngine()->GetGraphics()->SetBlendMode((DelGEGraphicsBlendMode)eMode);

	return 0;
}

SQInteger s_Graphics_GetBlendMode (HSQUIRRELVM v)
{
	sq_pushinteger			(v, (int)Globals::pGame->GetEngine()->GetGraphics()->GetBlendMode());

	return 1;
}

SQInteger s_Graphics_SetGlobalColor (HSQUIRRELVM v)
{
	SQInteger				iRed, iGreen, iBlue;
	SQInteger				iAlpha;

	sq_getinteger			(v, 2, &iRed);
	sq_getinteger			(v, 3, &iGreen);
	sq_getinteger			(v, 4, &iBlue);
	sq_getinteger			(v, 5, &iAlpha);

	Globals::pGame->GetEngine()->GetGraphics()->SetGlobalColor(Color(iRed, iGreen, iBlue, iAlpha));

	return 0;
}

SQInteger s_Graphics_GetGlobalColorRed (HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetGraphics()->GetGlobalColor_Red());

	return 1;
}

SQInteger s_Graphics_GetGlobalColorGreen (HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetGraphics()->GetGlobalColor_Green());

	return 1;
}

SQInteger s_Graphics_GetGlobalColorBlue (HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetGraphics()->GetGlobalColor_Blue());

	return 1;
}

SQInteger s_Graphics_GetGlobalColorAlpha (HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetGraphics()->GetGlobalColor_Alpha());

	return 1;
}

SQInteger s_Graphics_LoadTexture (HSQUIRRELVM v)
{
	const SQChar			*sTextureName;
	const SQChar			*sTextureFilepath;
	SQInteger				iMaskRed, iMaskGreen, iMaskBlue;
	SQInteger				eUWrapMode, eVWrapMode;

	iMaskRed = iMaskGreen = iMaskBlue = -1;

	sq_getstring			(v, 2, &sTextureName);
	sq_getstring			(v, 3, &sTextureFilepath);
	sq_getinteger			(v, 4, &iMaskRed);
	sq_getinteger			(v, 5, &iMaskGreen);
	sq_getinteger			(v, 6, &iMaskBlue);
	sq_getinteger			(v, 7, &eUWrapMode);
	sq_getinteger			(v, 8, &eVWrapMode);

	try
	{
		Texture* pTexture = Globals::pGame->GetEngine()->GetGraphics()->LoadTexture(sTextureFilepath, Color(iMaskRed, iMaskGreen, iMaskBlue), (GraphicsTexture_UVWrapMode)eUWrapMode, (GraphicsTexture_UVWrapMode)eVWrapMode);
		ResourceManager<Texture>::LoadResource(sTextureName, pTexture);
	}
	catch (DelGEError& error)
	{
		cout << "Error: " << error.description << endl;
	}

	return 0;
}

SQInteger s_Graphics_UnloadTexture (HSQUIRRELVM v)
{
	const SQChar			*sTextureName;

	sq_getstring			(v, 2, &sTextureName);

	ResourceManager<Texture>::UnloadResource(sTextureName);

	return 0;
}

SQInteger s_Graphics_LoadFont (HSQUIRRELVM v)
{
	const SQChar			*sFontName;
	const SQChar			*sFontFilepath;
	SQInteger				iFontSize;

	sq_getstring			(v, 2, &sFontName);
	sq_getstring			(v, 3, &sFontFilepath);
	sq_getinteger			(v, 4, &iFontSize);

	try
	{
		Font* pFont = Globals::pGame->GetEngine()->GetGraphics()->LoadFont(sFontFilepath, iFontSize);
		ResourceManager<Font>::LoadResource(sFontName, pFont);
	}
	catch (DelGEError& error)
	{
		cout << "Error: " << error.description << endl;
	}

	return 0;
}

SQInteger s_Graphics_UnloadFont (HSQUIRRELVM v)
{
	const SQChar			*sFontName;

	sq_getstring			(v, 2, &sFontName);

	ResourceManager<Font>::UnloadResource(sFontName);

	return 0;
}

SQInteger s_Graphics_DrawRect (HSQUIRRELVM v)
{
	SQFloat fX, fY, fWidth, fHeight;

	sq_getfloat				(v, 2, &fX);
	sq_getfloat				(v, 3, &fY);
	sq_getfloat				(v, 4, &fWidth);
	sq_getfloat				(v, 5, &fHeight);

	Globals::pGame->GetEngine()->GetGraphics()->DrawRect(fX, fY, fWidth, fHeight);

	return 0;
}

SQInteger s_Graphics_DrawTexture (HSQUIRRELVM v)
{
	const SQChar			*sTextureName;
	SQFloat					fX, fY;
	SQFloat					fWidth, fHeight;

	sq_getstring			(v, 2, &sTextureName);
	sq_getfloat				(v, 3, &fX);
	sq_getfloat				(v, 4, &fY);
	sq_getfloat				(v, 5, &fWidth);
	sq_getfloat				(v, 6, &fHeight);

	Texture *pTexture = ResourceManager<Texture>::GetResource(string(sTextureName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawTexture(pTexture, fX, fY, fWidth, fHeight);

	return 0;
}

SQInteger s_Graphics_DrawTextureArea (HSQUIRRELVM v)
{
	const SQChar			*sTextureName;
	SQFloat					fX, fY;
	SQFloat					fWidth, fHeight;
	SQInteger				iAreaX, iAreaY;
	SQInteger				iAreaWidth, iAreaHeight;

	sq_getstring			(v, 2, &sTextureName);
	sq_getfloat				(v, 3, &fX);
	sq_getfloat				(v, 4, &fY);
	sq_getfloat				(v, 5, &fWidth);
	sq_getfloat				(v, 6, &fHeight);
	sq_getinteger			(v, 7, &iAreaX);
	sq_getinteger			(v, 8, &iAreaY);
	sq_getinteger			(v, 9, &iAreaWidth);
	sq_getinteger			(v, 10, &iAreaHeight);

	Texture *pTexture = ResourceManager<Texture>::GetResource(string(sTextureName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawTextureArea(pTexture, fX, fY, fWidth, fHeight, iAreaX, iAreaY, iAreaWidth, iAreaHeight);

	return 0;
}

SQInteger s_Graphics_DrawText (HSQUIRRELVM v)
{
	const SQChar			*sText;
	SQFloat					fX, fY;
	const SQChar			*sFontName;

	sq_getstring			(v, 2, &sText);
	sq_getfloat				(v, 3, &fX);
	sq_getfloat				(v, 4, &fY);
	sq_getstring			(v, 5, &sFontName);

	Font *pFont = ResourceManager<Font>::GetResource(string(sFontName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawText(sText, fX, fY, pFont);

	return 0;
}

SQInteger s_Graphics_DrawMesh (HSQUIRRELVM v)
{
	const SQChar			*sMeshName;

	sq_getstring			(v, 2, &sMeshName);

	Mesh *pMesh = ResourceManager<Mesh>::GetResource(string(sMeshName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawMesh(pMesh);

	return 0;
}

SQInteger s_Graphics_DrawModel (HSQUIRRELVM v)
{
	const SQChar			*sModelName;

	sq_getstring			(v, 2, &sModelName);

	Model *pModel = ResourceManager<Model>::GetResource(string(sModelName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawModel(pModel);

	return 0;
}

SQInteger s_Graphics_DrawCamera (HSQUIRRELVM v)
{
	const SQChar			*sCameraName;

	sq_getstring			(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(string(sCameraName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawCamera(pCamera);

	return 0;
}

SQInteger s_Graphics_DrawSprite (HSQUIRRELVM v)
{
	const SQChar			*sSpriteName;

	sq_getstring			(v, 2, &sSpriteName);

	Sprite *pSprite = ResourceManager<Sprite>::GetResource(string(sSpriteName));

	Globals::pGame->GetEngine()->GetGraphics()->DrawSprite(pSprite);

	return 0;
}


SQInteger s_Graphics_TextWidth (HSQUIRRELVM v)
{
	const SQChar			*sText;
	const SQChar			*sFontName;

	sq_getstring			(v, 2, &sText);
	sq_getstring			(v, 3, &sFontName);

	Font *pFont = ResourceManager<Font>::GetResource(string(sFontName));

	sq_pushinteger(v, (int)Globals::pGame->GetEngine()->GetGraphics()->TextWidth(sText, pFont));

	return 1;
}

SQInteger s_Graphics_TextHeight (HSQUIRRELVM v)
{
	const SQChar			*sText;
	const SQChar			*sFontName;

	sq_getstring			(v, 2, &sText);
	sq_getstring			(v, 3, &sFontName);

	Font *pFont = ResourceManager<Font>::GetResource(string(sFontName));

	sq_pushinteger(v, (int)Globals::pGame->GetEngine()->GetGraphics()->TextHeight(sText, pFont));

	return 1;
}

SQInteger s_Graphics_BindTexture (HSQUIRRELVM v)
{
	const SQChar			*sTextureName;

	sTextureName = "";

	sq_getstring			(v, 2, &sTextureName);

	if (sTextureName != "")
	{
		Texture* pTexture = ResourceManager<Texture>::GetResource(string(sTextureName));
		Globals::pGame->GetEngine()->GetGraphics()->BindTexture(pTexture);
	}
	else
	{
		Globals::pGame->GetEngine()->GetGraphics()->BindTexture(NULL);
	}

	return 0;
}

SQInteger s_Graphics_PushWorldMatrix (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->PushWorldMatrix();

	return 0;
}

SQInteger s_Graphics_PopWorldMatrix (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->PopWorldMatrix();

	return 0;
}

SQInteger s_Graphics_TranslateWorld (HSQUIRRELVM v)
{
	SQFloat					fX, fY, fZ;

	sq_getfloat				(v, 2, &fX);
	sq_getfloat				(v, 3, &fY);
	sq_getfloat				(v, 4, &fZ);

	Matrix oCurrentWorld = Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	oCurrentWorld = oCurrentWorld * Matrix::Create3DTranslation(fX, fY, fZ);

	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(oCurrentWorld);

	return 0;
}

SQInteger s_Graphics_RotateWorldPitch (HSQUIRRELVM v)
{
	SQFloat					fRotation;

	sq_getfloat				(v, 2, &fRotation);

	Matrix oCurrentWorld = Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	oCurrentWorld = oCurrentWorld * Matrix::CreateRotationPitch(fRotation);

	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(oCurrentWorld);

	return 0;
}

SQInteger s_Graphics_RotateWorldYaw (HSQUIRRELVM v)
{
	SQFloat					fRotation;

	sq_getfloat				(v, 2, &fRotation);

	Matrix oCurrentWorld = Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	oCurrentWorld = oCurrentWorld * Matrix::CreateRotationYaw(fRotation);

	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(oCurrentWorld);

	return 0;
}

SQInteger s_Graphics_RotateWorldRoll (HSQUIRRELVM v)
{
	SQFloat					fRotation;

	sq_getfloat				(v, 2, &fRotation);

	Matrix oCurrentWorld = Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	oCurrentWorld = oCurrentWorld * Matrix::CreateRotationRoll(fRotation);

	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(oCurrentWorld);

	return 0;
}

SQInteger s_Graphics_ScaleWorld (HSQUIRRELVM v)
{
	SQFloat					fX, fY, fZ;

	sq_getfloat				(v, 2, &fX);
	sq_getfloat				(v, 3, &fY);
	sq_getfloat				(v, 4, &fZ);

	Matrix oCurrentWorld = Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	oCurrentWorld = oCurrentWorld * Matrix::Create3DScale(fX, fY, fZ);

	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(oCurrentWorld);

	return 0;
}

SQInteger s_Graphics_ResetWorld (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->SetModelViewMatrix(Matrix::Identity());

	return 0;
}

SQInteger s_Graphics_ResetProjection (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->Setup2DProjection(Globals::pGame->GetGraphicsWidth(), Globals::pGame->GetGraphicsHeight());

	return 0;
}

SQInteger s_Graphics_ProjectX (HSQUIRRELVM v)
{
	SQFloat					fX;

	sq_getfloat				(v, 2, &fX);

	Vector3 oVector = Vector3(fX, 0, 0);

	oVector = oVector * Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	sq_pushfloat			(v, oVector[0]);

	return 1;
}

SQInteger s_Graphics_ProjectY (HSQUIRRELVM v)
{
	SQFloat					fY;

	sq_getfloat				(v, 2, &fY);

	Vector3 oVector = Vector3(0, fY, 0);

	oVector = oVector * Globals::pGame->GetEngine()->GetGraphics()->GetModelViewMatrix();

	sq_pushfloat			(v, oVector[1]);

	return 1;
}

SQInteger s_Graphics_SetViewport (HSQUIRRELVM v)
{
	SQInteger				iX, iY, iWidth, iHeight;

	sq_getinteger			(v, 2, &iX);
	sq_getinteger			(v, 3, &iY);
	sq_getinteger			(v, 4, &iWidth);
	sq_getinteger			(v, 5, &iHeight);

	Globals::pGame->GetEngine()->GetGraphics()->SetViewport(iX, iY, iWidth, iHeight);

	return 0;
}

SQInteger s_Graphics_GetScreenWidth (HSQUIRRELVM v)
{
	sq_pushfloat(v, (float)Globals::pGame->GetGraphicsWidth());

	return 1;
}

SQInteger s_Graphics_GetScreenHeight (HSQUIRRELVM v)
{
	sq_pushfloat(v, (float)Globals::pGame->GetGraphicsHeight());

	return 1;
}

SQInteger s_Graphics_Begin2DRendering (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->Begin2DRendering();

	return 0;
}

SQInteger s_Graphics_Begin3DRendering (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->Begin3DRendering();

	return 0;
}

SQInteger s_Graphics_EnableLighting (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->EnableLighting();

	return 0;
}

SQInteger s_Graphics_DisableLighting (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->GetGraphics()->DisableLighting();

	return 0;
}

SQInteger s_Graphics_CreateCubeMesh	(HSQUIRRELVM v)
{
	const SQChar*			sMeshName;
	SQFloat					fWidth, fHeight, fDepth;
	SQFloat					fXOffset, fYOffset, fZOffset;

	fXOffset = fYOffset = fZOffset = 0.5f;

	sq_getstring			(v, 2, &sMeshName);
	sq_getfloat				(v, 3, &fWidth);
	sq_getfloat				(v, 4, &fHeight);
	sq_getfloat				(v, 5, &fDepth);
	sq_getfloat				(v, 6, &fXOffset);
	sq_getfloat				(v, 7, &fYOffset);
	sq_getfloat				(v, 8, &fZOffset);

	Mesh *pMesh = Mesh::CreateCube(fWidth, fHeight, fDepth,
								   fXOffset, fYOffset, fZOffset);

	ResourceManager<Mesh>::LoadResource(sMeshName, pMesh);

	return 0;
}

SQInteger s_Graphics_CreatePlaneMesh (HSQUIRRELVM v)
{
	const SQChar*			sMeshName;
	SQFloat					fWidth, fDepth;
	SQFloat					fXOffset, fZOffset;

	fXOffset = fZOffset = 0.5f;

	sq_getstring			(v, 2, &sMeshName);
	sq_getfloat				(v, 3, &fWidth);
	sq_getfloat				(v, 4, &fDepth);
	sq_getfloat				(v, 5, &fXOffset);
	sq_getfloat				(v, 6, &fZOffset);

	Mesh *pMesh = Mesh::CreatePlane(fWidth, fDepth, fXOffset, fZOffset);

	ResourceManager<Mesh>::LoadResource(sMeshName, pMesh);

	return 0;
}